//
//  WelcomeViewController.swift
//  ZHTQWeibo
//
//  Created by ZHTQ on 2018/9/19.
//  Copyright © 2018年 ZHTQ. All rights reserved.
//

import UIKit

class WelcomeViewController: UIViewController {
    /// 头像的底部约束
    @IBOutlet weak var iconBottonConstraint: NSLayoutConstraint!
    /// 头像
    @IBOutlet weak var iconImageView: UIImageView!
    /// 文字
    @IBOutlet weak var titleLable: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        iconImageView.layer.cornerRadius = 50
        iconImageView.clipsToBounds = true
        
        let user = UserAccount.loadUserAccount()
        
        let str = UserAccount.loadUserAccount()?.avatar_large
        
        assert(str != nil, "需要先获取授权")
        
        guard let url = URL(string: str!) else {
            return
        }
        
        iconImageView.sd_setImage(with: url, completed: nil)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        iconBottonConstraint.constant = UIScreen.main.bounds.height - iconBottonConstraint.constant * 2
        UIView.animate(withDuration: 2.0, animations: { // 头像上移动动画
            self.view.layoutIfNeeded()
        }) { (complety) in
            
            UIView.animate(withDuration: 1, animations: { // 文字显示动画
                self.titleLable.alpha = 1.0
            }, completion: { (_) in
                // 动画完成发送跳转主界面的通知
                NotificationCenter.default.post(name: NSNotification.Name(ZHTQViewControllerChangeNotification), object: true)
                
            })
        }
    }



}
